package org.examples.simplemulti;

import lombok.extern.slf4j.Slf4j;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.async.methods.SimpleResponseConsumer;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.util.Timeout;
import org.examples.VocsAsyncRequestProducer;

import java.util.concurrent.Future;


@Slf4j
public class UseBlockContentProducer {

    public static void main(final String[] args) throws Exception {

        final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
                .setSoTimeout(Timeout.ofSeconds(20))
                .build();

        final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
                .setIOReactorConfig(ioReactorConfig)
                .build();
        client.start();
        System.out.println("Executing request ");

        //    AudioAsyncResponseConsumer.recreateAudioFile();
        long startTimeMs = System.currentTimeMillis();
        final Future<SimpleHttpResponse> future = client.execute(
                new BlockContentProducer(),
                SimpleResponseConsumer.create(), null);
        SimpleHttpResponse resp = future.get();

        System.out.println(resp.getBodyText());
        System.out.println("Shutting down");
        client.close(CloseMode.GRACEFUL);
    }

}
